import { request } from '@/utils/request'
import type {
  KnowledgePage,
  KnowledgeParams,
  DoctorPage,
  TopDep,
  Image,
  ConsultOrderPreData,
  Consult,
  ConsultOrderItem,
  ConsultOrderListRes
} from '@/types/consult'
import type { ConsultType } from '@/enums'

// 分页获取知识列表（根据类型来的）
export const getKnowledgeList = (data: KnowledgeParams) => {
  return request<KnowledgePage>('/patient/home/knowledge', 'GET', data)
}

// 分页查询医生列表
export const getDoctorList = (data: { current: number; pageSize: number }) => {
  return request<DoctorPage>('/home/page/doc', 'GET', data)
}

// 关注（医生&文章）
export const like = (data: { id: string; type: 'topic' | 'knowledge' | 'doc' | 'disease' }) => {
  return request('/like', 'POST', data)
}

// 获取所有科室
export const getAllDep = () => {
  return request<TopDep[]>('/dep/all')
}

// 上传图片
export const uploadImg = (file: File) => {
  const data = new FormData()
  data.append('file', file)

  return request<Image>('/upload', 'POST', data)
}

// 获取预付信息
export const getOrderPre = (data: { type: ConsultType; illnessType: 0 | 1 }) => {
  return request<ConsultOrderPreData>('/patient/consult/order/pre', 'GET', data)
}

// 创建问诊订单
export const createConsultOrder = (data: Consult) => {
  return request<{ id: string }>('/patient/consult/order', 'POST', data)
}

// 根据订单创建支付链接
export const consultPay = (data: {
  paymentMethod: 0 | 1 | 2
  orderId: string
  payCallback: string
}) => {
  return request<{ payUrl: string }>('/patient/consult/pay', 'POST', data)
}

// 查询订单详情
export const getConsultOrderDetail = (orderId: string) => {
  return request<ConsultOrderItem>('/patient/consult/order/detail', 'GET', { orderId })
}

// 根据处方id，查询处方图片
export const getPrescriptionImg = (id: string) => {
  return request<{ url: string }>(`/patient/consult/prescription/${id}`)
}

// 评价医生
export const evaluateDoctor = (data: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: 0 | 1
}) => {
  return request('/patient/order/evaluate', 'POST', data)
}

// 获取问诊记录数据
export const getConsultOrderList = (data: {
  current: number
  pageSize: number
  type: ConsultType
}) => {
  return request<ConsultOrderListRes>('/patient/consult/order/list', 'GET', data)
}

// 取消问诊订单
export const cancelConsultOrder = (id: string) => {
  return request(`/patient/order/cancel/${id}`, 'PUT')
}

// 删除订单(Restful api)
export const delConsultOrder = (id: string) => {
  return request(`/patient/order/${id}`, 'DELETE')
}
